<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/static/include/taglib.jsp"%>

<!DOCTYPE html>
<html>
<head>
	<title>产品管理</title>
	<%@include file="/static/include/head.jsp" %>
</head>
<body>
	<form id="searchForm" modelAttribute="product" action="${ctx}/product/product/" method="post" class="breadcrumb form-inline">
        <%-- 分页 --%>
		<input id="currentPage" name="currentPage" type="hidden" value="${page.currentPage}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<%-- 过滤条件 --%>
		<label>产品名称 ：</label>
		<input type="text" id="name" name="sp_name_LIKE" value="${name_LIKE}" maxlength="100" class="form-control input-sm"/>
		&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
				<input id="btnAdd" class="btn btn-info" type="button" value="新增" onclick="formWindow()"/>
	</form>
	<tags:message content="${message}"/>
	<div class="table-responsive">
	<table id="contentTable" class="table table-striped table-bordered table-hover table-condensed">
		<thead>
		<tr>
			<%--主键不输出--%>
			<th class="center">
				<label>
					<input type="checkbox" />
				</label>
			</th>

			<th>产品名称</th>
			<th>产品编号</th>

			<th>价格</th>

			<th>成本</th>
			<th>重量</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.pageList}" var="product">
		<tr>
			<td class="center">
				<label>
					<input type="checkbox" value="${product.id}"/>
				</label>
			</td>

			<td>${product.name}</td>
			<td>${product.sn}</td>

			<td>${product.price}</td>

			<td>${product.cost}</td>
			<td>${product.weight}</td>
			<td>
				 
				<button type="button" class="btn btn-xs btn-info" onclick="formWindow('${product.id}','view')"
						data-toggle="tooltip" data-placement="right" title="查看">
					<span class="glyphicon glyphicon-search"></span>
				</button>
				<button type="button" class="btn btn-xs btn-warning" onclick="formWindow('${product.id}','edit')"
						data-toggle="tooltip" data-placement="left" title="修改">
					<span class="glyphicon glyphicon-pencil"></span>
				</button>
				<button type="button" class="btn btn-xs btn-danger" onclick="del('${product.id}')"
						data-toggle="tooltip" data-placement="right" title="删除">
					<span class="glyphicon glyphicon-trash"></span>
				</button>
			</td>
		</tr>
		</c:forEach>
		</tbody>
	</table>
	</div>

    <%-- pager bar（自定义标签）
    <j:page page="${page }" />
     --%>
	<%-- 如果不想用标签可以直接使用--%>
	${page }
	

	<%-- modal dialog --%>
    <%@include file="/static/include/modal.jsp"%>
</body>
<script type="text/javascript">
	$(function() {
		//on load do something
    });
	function formWindow(id,type) {
	    var url = '${ctx}/product/product/form' ;
	    if(id){
	        url += "?id="+id;
		}
        if(type){
            if(url.indexOf("?") != -1){
                url += "&type="+type;
            }else{
                url += "?type="+type;
            }
        }
		$("#formModal").modal({
			show:true,
			keyboard: true,
			remote: url
		});
    }
    /**
	 * 分页回调函数
     * @param n
     * @param s
     * @returns {boolean}
     */
    function page(n,s){
        $("#currentPage").val(n);
        $("#pageSize").val(s);
        $("#searchForm").submit();
        return false;
    }

    /**
     * 删除操作
     * @param id
     */
   function del(id) {
       confirm("确认要删除吗？", function(result){
       	if(result){
       		ajaxReq("${ctx}/product/product/delete?id=" + id, function(){
       			$("#btnSubmit").click(); //刷新列表
       		});
       	}
       });
   }
</script>
</html>
